Conditions | 3 |
Paths | 9 |
Total Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | inji.Chats = {}; |
||
3 | inji.Chats.get = function (id, params) { |
||
4 | var chatElement = $('#' + id); |
||
5 | var chat; |
||
|
|||
6 | if (chatElement.data('chats-index') === undefined) { |
||
7 | inji.Chats.chats.push({ |
||
8 | element: chatElement, |
||
9 | timer: null, |
||
10 | chatId: chatElement.data('chat-id'), |
||
11 | msgCount: chatElement.data('msg-count'), |
||
12 | perPage: 20, |
||
13 | lastEventDate: chatElement.data('last-event-date'), |
||
14 | reverse: params.reverse ? true : false, |
||
15 | scrollable: true, |
||
16 | members: {}, |
||
17 | checkoutMembers: function () { |
||
18 | var members = this.members; |
||
19 | $.each($('[data-chat_member_status'), function () { |
||
20 | var el = $(this); |
||
21 | if (members[el.data('chat_member_status')]) { |
||
22 | if (el.data('ontext')) { |
||
23 | el.html(el.data('ontext')); |
||
24 | } |
||
25 | if (el.data('onclass')) { |
||
26 | if (el.data('offclass') && el.hasClass(el.data('offclass'))) { |
||
27 | el.removeClass(el.data('offclass')); |
||
28 | } |
||
29 | el.addClass(el.data('onclass')); |
||
30 | } |
||
31 | } else { |
||
32 | if (el.data('offtext')) { |
||
33 | el.html(el.data('offtext')); |
||
34 | } |
||
35 | if (el.data('offclass')) { |
||
36 | if (el.data('onclass') && el.hasClass(el.data('onclass'))) { |
||
37 | el.removeClass(el.data('onclass')); |
||
38 | } |
||
39 | el.addClass(el.data('offclass')); |
||
40 | } |
||
41 | } |
||
42 | }) |
||
43 | }, |
||
44 | deleteMsg: function (id, chatId) { |
||
45 | inji.Server.request({ |
||
46 | url: 'chats/deleteMsg/' + id, |
||
47 | success: function () { |
||
48 | $('#chat' + chatId + 'msg' + id).remove(); |
||
49 | } |
||
50 | }); |
||
51 | }, |
||
52 | banUser: function (msgId, chatId) { |
||
53 | inji.Server.request({ |
||
54 | url: 'chats/banUser/' + msgId, |
||
55 | success: function (msgIds) { |
||
56 | for (var key in msgIds) { |
||
57 | $('#chat' + chatId + 'msg' + key).remove(); |
||
58 | } |
||
59 | } |
||
60 | }); |
||
61 | }, |
||
62 | }); |
||
63 | var index = inji.Chats.chats.length - 1 |
||
64 | chatElement.data('chats-index', index); |
||
65 | inji.Chats.init(index); |
||
66 | return inji.Chats.chats[index]; |
||
67 | } |
||
68 | return inji.Chats.chats[chatElement.data('chats-index')]; |
||
69 | } |
||
70 | inji.Chats.init = function (chatIndex) { |
||
135 | } |